package projetjava;

import Composite.Element;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.Observable;
import java.util.Observer;
import javax.swing.*;


public class ApercuPhotoDossier extends JPanel{
   
    private Dimension dim = new Dimension(200,200);
    private PanneauPhoto photo;
    
    public ApercuPhotoDossier(){
         
        this.setLayout(new BorderLayout());
        this.add(Box.createHorizontalStrut(8), BorderLayout.WEST);
        this.add(Box.createHorizontalStrut(8), BorderLayout.EAST);
        this.add(Box.createVerticalStrut(8), BorderLayout.NORTH);
        this.add(Box.createVerticalStrut(8), BorderLayout.SOUTH);  

        this.photo = new PanneauPhoto();

        this.add(photo,BorderLayout.CENTER);
    }
    
    
    
    public Dimension getSize() {
        return dim;
    }
    public Dimension getPreferredSize() {
        return dim;
    }
    public Dimension getMaximumSize() {
        return dim;
    }
    public Dimension getMinimumSize() {
        return dim;
    }
}


class PanneauPhoto extends JPanel implements Observer{

    private Element maPhoto;
    private BufferedImage apercu;
    
    public PanneauPhoto(){
        
        this.apercu=null;
        this.maPhoto=null;
        GestionnaireDisqueDur.getInstance().addObserver(this);
        this.setLayout(null);
        this.setBackground(Color.BLACK);
        
    }
    
    public void update(Observable o, Object arg) {

        this.maPhoto=(Element) arg;
        apercu = this.maPhoto.getApercu("apercus/");
        this.repaint();
    }
    
    public void paintComponent(Graphics g){
        super.paintComponent(g);
        if (apercu == null) return;       
        Graphics2D g2 = (Graphics2D) g;
        g2.drawImage(apercu,(int)(this.getSize().getWidth()-apercu.getWidth())/2,(int)(this.getSize().getHeight()-apercu.getHeight())/2,null);
    
    }
    
}
